#include <stdio.h>
#include "getop.h"
#include "errlib.h"
#include "client_backend.h"
#include "frontend.h"

/* displays the front-end */	
void
frontend(formulaT * formula)
{
	int end, error;

	for (end = error = 0; !end; error = 0)
	{
		if ((error = getOperand(&(formula->op1)))) 
		{
			warn("Input Error: Invalid operand");
			continue; 
		}
		if ((error = getOperator(&(formula->opcode)))) 
		{
			warn("Input Error: Invalid operator");
			continue;
		}
		if ((error = getOperand(&(formula->op2)))) 
		{
			warn("Input Error: Invalid operand"); 
			continue;
		}
		
		end = 1;
	}
}


/* print operation requested and answer received */
void
print_answer(formulaT * formula)
{
	char c;

	switch(formula->opcode)
	{
		case ADD: c = '+'; break;
		case SUB: c = '-'; break;
		case MULT: c = '*'; break;
		case DIV: c = '/'; break;
		default: c = ' '; break;
	}

	printf("=> %lg %c %lg = %lg\n", 
		formula->op1, c, formula->op2, formula->ans);
}
